﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Urb.Weather.Core.MeasureUnit;
using System.Globalization;

namespace Urb.Weather.Yahoo
{
    public class YahooWeatherUri
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed")]
        public YahooWeatherUri(string locationId, TemperatureUnit temperatureUnit = TemperatureUnit.Fahrenheit)
        {
            if (locationId == null)
                throw new ArgumentNullException("locationId");

            switch (temperatureUnit)
            {
                case TemperatureUnit.Celsius:
                case TemperatureUnit.Fahrenheit:
                    break;
                default:
                    throw new NotSupportedException();
            }

            LocationId = locationId.Trim();
            TemperatureUnit = temperatureUnit;
        }

        public string LocationId { get; private set; }
        public TemperatureUnit TemperatureUnit { get; set; }

        public override string ToString()
        {
            switch (TemperatureUnit)
            {
                case TemperatureUnit.Fahrenheit:
                    return string.Format(CultureInfo.InvariantCulture, "http://weather.yahooapis.com/forecastrss?w={0}", LocationId);
                case TemperatureUnit.Celsius:
                    return string.Format(CultureInfo.InvariantCulture, "http://weather.yahooapis.com/forecastrss?w={0}&u=c", LocationId);
                default:
                    return null;
            }
        }
    }
}
